Back to course home
0% completed
Vote For New Content
Oracle Hard
Integer to English Words (hard)
Solution: Integer to English Words
Trapping Rain Water (hard)
Solution: Trapping Rain Water
First Missing Positive (hard)
Solution: First Missing Positive
Merge K Sorted Lists (hard)
Solution: Merge K Sorted Lists
Max Points on a Line (hard)
Solution: Max Points on a Line
Sudoku Solver (hard)
Solution: Sudoku Solver
Longest Valid Parentheses (hard)
Solution: Longest Valid Parentheses
Remove Nth Node From End of List (Medium)
Solution: Remove Nth Node From End of List
Median of Two Sorted Arrays (hard)
Solution: Median of Two Sorted Arrays
Constrained Subsequence Sum (hard)
Solution: Constrained Subsequence Sum
Delete Node in a BST (medium)
Problem Statement
Given a root node of the binary search tree, and an integer value key, return the root of the updated BST after deleting the node having a value equal to key.
If BST doesn't contain the node having value equal to key, return the same binary tree.
Examples
Example 1:
- Input:
[8, 3, 10, 1, 6, null, 14, null, null, 4, 7, 13], key =3
- Expected Output:
[8, 4, 10, 1, 6, null, 14, null, null, null, 7, 13] - Justification: After removing the node with value
3, its right subtree's smallest value (4) replaces it to maintain the BST structure.
Example 2:
- Input:
[20, 10, 30, null, 15, 25, 35], key =10
- Expected Output:
[20, 15, 30, null, null, 25, 35] - Justification: The node
10is removed and replaced by its right child15to keep the tree's integrity.
Example 3:
- Input:
[50, 30, 70, 20, 40, 60, 80], key =10
- Expected Output:
[50, 30, 70, 20, 40, 60, 80] - Justification: The BST doesn't contain the node with value 10. So, it returns the original BST.
Try it yourself
Try solving this question here:
Java
. . . .
Solution: Meeting Rooms II
Solution: Delete Node in a BST
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself